package scm.client;

import java.util.ArrayList;

import scm.message.*;
import scm.server.MailServer;
/**
 * 
 * @author Benito
 *
 */
public class MailClient {

	private ArrayList<Message> messagelist = null;
	private String name; 
	private MailServer server;
	private int messageindex;
	
	public MailClient(String username){
		this.name = username;
		messageindex =0;
		messagelist = new ArrayList<Message>();
	}
	
	public int checkMessage(){
		return messagelist.size();
	}
	
	public void reciveMessage(Message message){
		messagelist.add(message);
	}
	
	public Message readNextMessage(){
		if(messageindex<messagelist.size()){
			messageindex++;
			return messagelist.get(messageindex-1);
		}
			
		return null;
	}

	
	public void sendMessage(Message message){
		message.setSender(name);
		server.post(message);
	}
	public MailServer getServer() {
		return server;
	}

	public void setServer(MailServer server) {
		this.server = server;
	}
	
	public static void main(){
		
		MailClient m = new MailClient("Herlan");
		Message sms = new Message("barin_2@hotmail.com","emanuel_leon_17@hotmail.com","hola","hola como estas");
		m.messagelist.add(sms);
		
		m.server.post(sms);
		
	}
	
	
}
